/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.*;
import java.util.ArrayList;

/**
 *
 * @author Jason Sorbello
 */
public class MySQLAirportDAO implements AirportDAO {

    private ResultSet rs;
    private Statement stmt;

    public ArrayList getAirports() {

        MySQLDAOFactory getAirportsFactory = new MySQLDAOFactory();

        ArrayList<String> airportList = new ArrayList<String>();

        Connection con = MySQLDAOFactory.createConnection();
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("SELECT AIRPORT_NAME FROM AIRPORT");

            while (rs.next()) {
                airportList.add((rs.getString("AIRPORT_NAME")));
            }
        } catch (Exception e) {
            System.out.println("Error message " + e.getMessage());
        }
        return airportList;
    }

    public void deleteAirport(String delAirport) {

        Connection con = MySQLDAOFactory.createConnection();
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("DELETE FROM `AIRPORT` WHERE AIRPORT_NAME = '" + delAirport + "';");

        } catch (Exception e) {
            System.out.println("Error message " + e.getMessage());
        }
    }

    public void makeAirport(String name, String location, String tax) {
        Connection con = MySQLDAOFactory.createConnection();
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("INSERT INTO `AIRPORT` VALUES ( '" + name + "', '" + location + "', '" + tax + "' );");

        } catch (Exception e) {
            System.out.println("Error message " + e.getMessage());
        }
    }

    public void editAirport(String columnName, String value, String airportName) {
        Connection con = MySQLDAOFactory.createConnection();
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("UPDATE `AIRPORT` SET " + columnName + " = '" + value + "' WHERE AIRPORT_NAME = '" + airportName + "';");

        } catch (Exception e) {
            System.out.println("Error message " + e.getMessage());
        }
    }
}
